// *********************************************************
//      Copyright (c) Kosta Gaitanis
//      All rights reserved
//
//      k.gaitanis@gmail.com
//
// *********************************************************

#ifndef TEXTURE_H
#define TEXTURE_H

#include <QMetaType>
#include <QtOpenGL/QtOpenGL>

/**
 * \class Texture
 * \brief This class represents an OpenGL Texture represented as a QImage.
 * \author Kosta Gaitanis
 */
class Texture
{
public:
    /**
     * Constructs a new texture with the given name.
     *
     * @param name The name of the texture.
     */
    Texture(const QString& name, const QImage& image);

    /**
     * Destructor
     */
    ~Texture();

    /**
     * Changes the name of this texture.
     * @param name The new name.
     */
    void setName(const QString &name);

    /**
     * @return The name of this texture.
     */
    QString getName() const;

    /**
     * Sets the image of this texture.
     * @param imahe The image that will be used for this texture.
     */
    void setImage(const QImage& image);

    /**
     * @return The image of this texture.
     */
    QImage getImage() const;

    /**
     * @return The unique GL texture Id as assigned by the GLEngine.
     */
    GLuint getTextureId() const;

    /**
     * @brief initializes the texture.
     * Generates a texture Id and loads the image into GPU.
     */
    void initializeGL();

    /**
     * @brief Binds this texture and sets the texture properties.
     */
    void paintGL() const;

private:
    Q_DISABLE_COPY(Texture)

    QString m_name;                 /// > The name of this texture.
    GLuint m_textureId;             /// > The unique GL texture id.
    QImage m_image;                 /// > The image of the texture.

    bool m_isInitialized;           /// > True if the image has been loaded into GPU.

};

Q_DECLARE_METATYPE(const Texture*)

#endif // TEXTURE_H
